﻿using Microsoft.AspNetCore.Http;
using SaaS.Model.Enums;
using XCore.Dependency;
using XCore.Extensions;

namespace Web.System.Utils
{
    /// <summary>
    /// 总管理当前登录Session
    /// </summary>
    public class SystemSession : IScopedDependency
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        public SystemSession(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }

        /// <summary>
        /// 当前登录用户名
        /// </summary>
        public string UserName => _httpContextAccessor.HttpContext.GetClaimValue("UserName");

        /// <summary>
        /// 当前登录管理员ID
        /// </summary>
        public int AdminId => _httpContextAccessor.HttpContext.GetUserId("AdminId");

        public static implicit operator int(SystemSession session)
        {
            return session.AdminId;
        }
    }
}
